package com.ultrasoft.farmasoft.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ultrasoft.farmasoft.domain.Operation;

@Repository(value = "operationDao")
@Transactional(readOnly = false)
public class OperationDaoImpl implements OperationDao {

	private EntityManager em = null;	
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}
	public List<Operation> getListOperation() {
		TypedQuery<Operation> q = em.createNamedQuery("Operation.findAll",Operation.class);
    	return q.getResultList();
	}
	public Operation findByOperationId(Short operationId) {
		Operation res=null;
		try {
			res=em.find(Operation.class,operationId);
		} catch (Exception e) {
			// TODO: handle exception
		}
    	return res;
	}
	public void update(Operation operation) {
		em.merge(operation);
	}
	public void remove(Operation operation) {
		em.remove(em.getReference(Operation.class,operation.getOperationId()));
	}
	public void add(Operation operation) {
		em.persist(operation);
	}

}
